<template>
  <z-paging ref="paging" v-model="items" @query="queryList" :default-page-size="20">
    <view class="item-wrap">
      <view class="item"
        v-for="(item, index) in items" :key="index"
        @click="proxy.$util.navigateTo('/pages/webview/index', {src: 'pages/' + item.id})">
        <view class="item-top">
          <view class="left" v-if="item.image_format"><image class="image" :src="item.image_format" mode="widthFix" /></view>
          <view class="item-title">{{ item.title }}</view>
        </view>
        <view class="item-updated-at">{{ item.updated_at }}</view>
      </view>
    </view>
  </z-paging>
</template>

<script setup>
const { proxy } = getCurrentInstance()
proxy.$util.setTabBarLanguage()
const paging = ref(null)

const items = ref([])

const queryList = (pageNo, pageSize) => {
  const params = {
    pageNo: pageNo,
    pageSize: pageSize,
  }

  proxy.$http.get('articles', params).then(res => {
    paging.value.complete(res.data)
  })
}
</script>

<style lang="scss" scoped>
.item-wrap {
  margin-top: 10px;
  .item {
    background-color: #fff;
    padding: 26rpx 20rpx;
    margin-bottom: 20rpx;

    .item-top {
      display: flex;
      margin-bottom: 20rpx;

      .left {
        flex: 0 0 200rpx;
        margin-right: 20rpx;

        .image {
          width: 100%;
          height: 100%;
        }
      }
    }

    .item-title {
      font-size: 32rpx;
      font-weight: bold;
    }

    .item-updated-at {
      color: #666;
      font-size: 24rpx;
    }
  }
}
</style>
